import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:safetymonitor/app/components/custom_app_bar.dart';
import 'package:safetymonitor/app/components/custom_date_type.dart';
import 'package:safetymonitor/app/components/custom_modele/custom_title_chart_page.dart';
import 'package:safetymonitor/app/core/core.dart';
import 'package:safetymonitor/app/core/ext/ext.dart';
import 'package:safetymonitor/app/core/ext/widget_extension.dart';
import 'package:safetymonitor/generated/assets.dart';
import 'package:safetymonitor/modules/home/new_alarm_warning_page/no_completed/controller.dart';
import 'controller.dart';

///详情
class AlarmDetailPage extends StatelessWidget {
  AlarmDetailPage({super.key});

  final controller = Get.put(AlarmDetailController());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: AppColors.bg_color_grey,
      appBar: CustomAppBar(
        backgroundColor: const Color(0xFF1847E3),
        title: Text(
          '详情',
          style: TextStyle(
              color: Colors.white, fontSize: 16.w, fontWeight: FontWeight.w500),
        ),
        leading: const BackButton(
          color: Colors.white,
        ),
      ),
      body: GetBuilder(
        init: controller,
        builder: (_) {
          return Container(
              color: const Color(0xFFF5F5F6),
              child: Stack(
                children: [_top(), _getNormalView()],
              ));
        },
      ),
      bottomSheet:    controller.entity.supervisionStatusStr != '0'? //0、无操作按钮权限
       Container(
        height: 60.w,
        alignment: Alignment.center,
        padding: EdgeInsets.symmetric(horizontal: 16.w),
        decoration: BoxDecoration(
          color: Colors.white,
          boxShadow: [
            BoxShadow(
              color: const Color(0xffBCBCC5).withOpacity(0.3), // 阴影颜色
              offset: const Offset(0, -5), // 阴影的偏移量，向上偏移，即上方阴影
              blurRadius: 10.0, // 阴影的模糊半径
              spreadRadius: 2.0, // 阴影的扩散半径
            ),
          ],
        ),
        child: Container(
            height: 40.w,
            alignment: Alignment.center,
            decoration: BoxDecoration(
                color: const Color(0xFF1847E3),
                borderRadius: BorderRadius.all(
                  Radius.circular(20.w),
                )),
            child: Text(
              controller.entity.supervisionStatusStr == '1'|| controller.entity.supervisionStatusStr == '2'? '督办' :   controller.entity.supervisionStatusStr == '3'?'派发':'处置',
              style: TextStyle(
                fontSize: 16.sp,
                color: const Color(0xffffffff),
              ),
            )).clickOnce(() {
             Get.find<NoCompletedController>().onClickOperateDialog(controller.entity,closeOverlays:true );
        }),
      ):null,
    );
  }

  Widget _top() {
    return Container(
      height: 100.w,
      width: AppDimens.sh,
      color: const Color(0xFF1847E3),
    );
  }

  /// 基本信息
  Widget _getNormalView() {
    return Column(children: [
      Container(
        padding: EdgeInsets.symmetric(horizontal: 16.w),
        child: SingleChildScrollView(
          child: Column(
            children: [
              AppGaps.vGap16,
              CustomTitleChartPage(
                contentPadding:
                EdgeInsets.only(right: 16.w, left: 16.w, top: 16.w),
                title: controller.entity.companyName,
                titleRightWidget:getStatueView(controller.entity.disposalStatus),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    _getTextView(title: '${CustomDateType.getDataType(controller.entity.dataType)}级别:',
                        value: CustomDateType.getAlarmType(controller.entity.alarmLevel, controller.entity.dataType)),
                    _getTextView(title: '系统-类别:', value: controller.entity.categoryZh),
                    _getTextView(title: '报警类型:', value: CustomDateType.getAlarmTypeByValue(controller.entity.dataType)),
                    _getTextView(title: '点位:', value: controller.entity.deviceCode),
                    _getTextView(title: '内部设置阈值:', value:'${controller.entity.internalVal}'),
                    _getTextView(title: '政府规定阈值:', value: '${controller.entity.governmentVal }'),
                    _getTextView(title: '${CustomDateType.getDataType(controller.entity.dataType)}值:', value: '${controller.entity.val==0?'': controller.entity.val}'),
                    _getTextView(title: '报警时长:', value: '${controller.entity.alarmTimeMin}分钟'),
                    _getTextView(title: '报警时间:', value:'${controller.entity.alarmStartTime}'.millTS2Str()),
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    ]);
  }
  /// 处置进度状态（1未处置，2.超时未处置，3.处置中，4.超时处置中，5.及时完成，6.超时完成）
  Widget getStatueView(String status) {
    String name = '';
    Color? bgColor;
    switch (status) {
      case '1':
        name = '未处置';
        break;
      case '2':
        name = '超时未处置';
        bgColor = const Color(0xFFFE9843);
        return Stack(
          alignment: Alignment.centerLeft,
          children: [
            SvgPicture.asset(
              height: 12.w,
              width: 12.w,
              Assets.svgBgStatue,
              fit: BoxFit.cover,
              colorFilter:  ColorFilter.mode(bgColor, BlendMode.srcIn),
            ),
            Positioned(
              left: 16.w,
              child: Text(
                name,
                style: TextStyle(
                  fontSize: 10.sp,
                  height: 1.2,
                  fontWeight: FontWeight.w400,
                  color: const Color(0xFF3F425B),
                ),
              ),
            ),
          ],
        );
      case '3':
        name = '处置中';
        bgColor = const Color(0xFFFE9843);
        break;
      case '4':
        name = '超时处置中';
        bgColor = const Color(0xFF63C320);
        return Stack(
          alignment: Alignment.centerLeft,
          children: [
            SvgPicture.asset(
              height: 12.w,
              width: 12.w,
              Assets.svgBgStatue,
              fit: BoxFit.cover,
              colorFilter:  ColorFilter.mode(bgColor, BlendMode.srcIn),
            ),
            Positioned(
              left: 16.w,
              child: Text(
                name,
                style: TextStyle(
                  fontSize: 10.sp,
                  height: 1.2,
                  fontWeight: FontWeight.w400,
                  color: const Color(0xFF3F425B),
                ),
              ),
            ),
          ],
        );
      case '5':
        name = '及时完成';
        bgColor = const Color(0xFF63C320);
        return Stack(
          alignment: Alignment.centerLeft,
          children: [
            SvgPicture.asset(
              height: 12.w,
              width: 12.w,
              Assets.svgBgStatue,
              fit: BoxFit.cover,
              colorFilter:  ColorFilter.mode(bgColor, BlendMode.srcIn),
            ),
            Positioned(
              left: 16.w,
              child: Text(
                name,
                style: TextStyle(
                  fontSize: 10.sp,
                  height: 1.2,
                  fontWeight: FontWeight.w400,
                  color: const Color(0xFF3F425B),
                ),
              ),
            ),
          ],
        );
      case '6':
        name = '超时完成';
        bgColor = const Color(0xFF63C320);
        return Stack(
          alignment: Alignment.centerLeft,
          children: [
            SvgPicture.asset(
              height: 12.w,
              width: 12.w,
              Assets.svgBgStatue,
              fit: BoxFit.cover,
              colorFilter:  ColorFilter.mode(bgColor, BlendMode.srcIn),
            ),
            Positioned(
              left: 16.w,
              child: Text(
                name,
                style: TextStyle(
                  fontSize: 10.sp,
                  height: 1.2,
                  fontWeight: FontWeight.w400,
                  color: const Color(0xFF3F425B),
                ),
              ),
            ),
          ],
        );
    }
    return SizedBox(
      child: Stack(
        alignment: Alignment.centerRight,
        children: [
          SvgPicture.asset(
            Assets.svgBgStatue,
            height: 12.w,
            width: 12.w,
            fit: BoxFit.cover,
            colorFilter: bgColor == null ? null : ColorFilter.mode(bgColor, BlendMode.srcIn),
          ),
          Text(
            name,
            style: TextStyle(
              fontSize: 14.sp,
              height: 1.2,
              fontWeight: FontWeight.w400,
              color: const Color(0xFF3F425B),
            ),
          ),
        ],
      ),
    );
  }

  /// 获取字段显示
  Widget _getTextView({required String title, required String value}) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              title,
              style: TextStyle(
                fontSize: 14.sp,
                height: 1.2,
                fontWeight: FontWeight.w400,
                color: const Color(0xffC7CEE5),
              ),
            ),
            AppGaps.hGap6,
            Expanded(
                child: Text(
                  value,
                  style: TextStyle(
                    fontSize: 14.sp,
                    height: 1.2,
                    fontWeight: FontWeight.w400,
                    color: const Color(0xff1D3452),
                  ),
                ))
          ],
        ),
        AppGaps.vGap10,
      ],
    );
  }
}
